// zh_jypx/pages/my/gift_order.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    list:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    // —————————————— 获取网址——————————
    app.util.request({
      "url": "entry/wxapp/Attachurl",
      'cachetime': '0',
      success: function (res) {
        that.setData({
          url: res.data
        })
      }
    })
    that.list()
  },

  list:function(e){
    var that=this;
    var page = that.data.page
    console.log(page)
    var user_id = wx.getStorageSync('user_msg').id
    console.log(user_id)
    app.util.request({
      "url": "entry/wxapp/MyExchangeRecord",
      'cachetime': '0',
      data: {
        page: page,
        user_id: user_id
      },
      success: function (res) {
        console.log(res.data.list)
        if (res.data.code==200) {
          var list=that.data.list
          console.log(list)
          list = list.concat(res.data.list)
          console.log(list)
          that.setData({
            list: list,
            page: page + 1
          })
        }
      }
    })
  },

  /*点击进入兑换详情 */
  // gift_detail: function (e) {
  //   var dh_id=e.currentTarget.dataset.id
  //   console.log(dh_id)
  //   wx: wx.navigateTo({
  //     url: 'gift_detail?dh_id=' + dh_id,
  //   })
  // },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var that = this;
    that.setData({
      page:1,
      list:[]
    })
    that.list()

    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    // that.order()
    var page = that.data.page
    console.log(page)
    // that.setData({
    //   page: page + 1
    // })
    that.list()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})